import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class CustomTextField extends StatelessWidget {
  final TextEditingController controller;
  final bool? obscureText;
  final Widget? suffixIcon;
  final String? label;
  final String? hintText;
  final EdgeInsetsGeometry? margin;
  final ValueChanged<String>? onChanged;
  final int? maxLength;
  final TextInputType? keyboardType;
  final TextInputAction? textInputAction;
  final List<TextInputFormatter>? inputFormatters;

  const CustomTextField({
    Key? key,
    required this.controller,
    this.obscureText,
    this.suffixIcon,
    this.hintText,
    this.margin,
    this.onChanged,
    this.maxLength,
    this.keyboardType,
    this.textInputAction,
    this.label,
    this.inputFormatters,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: [
        Offstage(
            child: Container(
              margin: const EdgeInsets.only(top: 20, bottom: 5),
              child: Text(
                label ?? '',
                style: const TextStyle(fontSize: 16),
              ),
            ),
            offstage: label == null),
        TextField(
          autocorrect: false,
          textInputAction: textInputAction,
          inputFormatters: inputFormatters,
          cursorColor: Colors.black,
          controller: controller,
          maxLength: maxLength,
          keyboardType: keyboardType,
          obscureText: obscureText ?? false,
          style: const TextStyle(color: Colors.black),
          onChanged: onChanged,
          decoration: InputDecoration(
            enabledBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.grey[300]!),
            ),
            focusedBorder: UnderlineInputBorder(
              borderSide: BorderSide(color: Colors.grey[300]!),
            ),
            contentPadding: const EdgeInsets.symmetric(vertical: 6),
            suffixIcon: suffixIcon,
            hintText: hintText ?? '',
            hintStyle: const TextStyle(color: Colors.grey),
          ),
        ),
      ],
    );
  }
}
